namespace Microsoft.ServiceModel.Samples.Discovery.Protocol
{
    using System;
    using System.Xml;
    using System.Xml.Serialization;
    using System.ServiceModel;

    
    [XmlType(Namespace = ProtocolStrings.Namespace)]
    [XmlRoot(ProtocolStrings.ByeElement,
        Namespace = ProtocolStrings.Namespace)]
    public class Bye : ServiceProperties
    {
        bool metadataVersionFieldSpecified;

        [XmlIgnore]
        public bool MetadataVersionSpecified
        {
            get
            {
                return this.metadataVersionFieldSpecified;
            }
            set
            {
                this.metadataVersionFieldSpecified = value;
            }
        }

        public static Bye FromServiceProperties(
            ServiceProperties serviceProperties)
        {
            if (serviceProperties == null)
                throw new ArgumentNullException("serviceProperties");

            Bye bye = new Bye();

            bye.EndpointAddress = serviceProperties.EndpointAddress;
            bye.MetadataVersion = serviceProperties.MetadataVersion;
            bye.MetadataVersionSpecified = true;
            bye.Types = serviceProperties.Types;
            bye.Scopes = serviceProperties.Scopes;
            bye.XAddrs = serviceProperties.XAddrs;
            bye.AnyElements = serviceProperties.AnyElements;
            bye.AnyAttributes = serviceProperties.AnyAttributes;

            return bye;
        }

        public bool IsValid()
        {
            return (this.EndpointAddress != null);
        }
    }
}
